﻿@{
    // odd formatting in this file is to cause more attractive results in the output.
    var items = (IEnumerable<dynamic>)Enumerable.Cast<dynamic>(Model);
    if (!HasText(Model.Text)) {
        @DisplayChildren(Model)
    } else {
        string requestUrl = Request.Path.Replace(Request.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant();
        string modelUrl = Model.Href.Replace(Request.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant();
        if ((!string.IsNullOrEmpty(modelUrl) && requestUrl.StartsWith(modelUrl)) || requestUrl == modelUrl) { 
	        Model.Classes.Add("current");
        }
        if (items.Any()) {
            Model.Classes.Add("has-children");  
        }
        if (!string.IsNullOrEmpty(Model.IdHint as string)) {
            Model.Id = Model.IdHint;
        }        
        
        var tag = Tag(Model, "li");       
    
        @tag.StartElement
        <a href="@Model.Href">@Model.Text</a>
        if (items.Any()) {
            <ul>
            @DisplayChildren(Model)
            </ul>
        }
        @tag.EndElement        
    }
}